package com.carl.lambda.simpleLambda.damand01;


import com.carl.lambda.simpleLambda.lambda1.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 调用Collection.sort()方法,通过定制排序两个employee(先按年龄比,年龄相同按姓名比),使用lambda作为参数传递
 */
public class LambdaTest {
    List<Employee> employees = Arrays.asList(
            new Employee("张三",18,99.99),
            new Employee("李四",28,999.99),
            new Employee("王五",32,9999.99),
            new Employee("赵六",48,9999.99),
            new Employee("钱七",58,9999.99)
    );


    @Test
    public void lambdaTest(){
        employees.sort((e1, e2) -> {
            if (Objects.equals(e1.getAge(), e2.getAge())) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return -Integer.compare(e1.getAge(), e2.getAge());
            }
        });

        for (Employee employee : employees) {
            System.out.println(employee);
        }

    }



}
